import { _decorator, Component, Label, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('timeBg')
export class timeBg extends Component {

    private time:number = 10


    start() {

        


    }


    starTimeCheck(){
        // 以秒为单位的时间间隔
        let interval = 1;
        this.schedule(this.callback, interval);
    }

    callback(){
        if(this.time == 0){
            this.unschedule(this.callback);
            //时间到。失败
            console.log('游戏失败')
        }
        this.time--;
        let timeCur = this.formatTime(this.time)
        this.node.getChildByName('time').getComponent(Label).string = timeCur



    }

    formatTime(seconds: number): string {
        const minutes = Math.floor(seconds / 60);  // 计算分钟数
        const remainingSeconds = seconds % 60;    // 计算剩余的秒数
        if(remainingSeconds<10){
            return `0${minutes}:0${remainingSeconds}`;
        }else{
            return `0${minutes}:${remainingSeconds}`;
        }
       
    }
}


